package configuration单例;

/**
 * 意义不大 因为 spring提供功能直接让返回对象作为单例
 *
 * @author yuank
 * @version 1.0.0
 * @date 2024/12/19 9:41:03
 */
class HungerSingleton{
    private static HungerSingleton instance = new HungerSingleton();
    public static HungerSingleton getInstance(){
        return instance;
    }
    private HungerSingleton(){} // 权限阻止了偷偷new的可能 要new只能通过静态类方法
}

//todo
class DoubleSingleton{

}

// 可以把synchronized加锁范围减少到↑↑
class FullSingleton {
    private static FullSingleton instance;
    public static synchronized FullSingleton getInstance() {
        if (instance != null) { return instance;
        } else {return new FullSingleton();}
    }
    private FullSingleton(){} // 关键在于权限,而不是构造的空
}
